<template>
	<view>
		<u-swiper :list="lun" :height="250" :effect3d="true" :interval="3000" @click="click(idd)">
		</u-swiper>
		<uni-grid>
			<view class="u-flex " style="width: 100%;padding: 30rpx;" >
				<view @click="shou" style="width: 50%;border: 1px solid #CCCCCC;" class="u-text-center">
					<image src="../../../../static/uview/example/js_select_bak.png" style="width: 100rpx;height: 100rpx;"></image>
					<view>搜索</view>
				</view>
				<view @click="fenlei2" style="width: 50%;border: 1px solid #CCCCCC;" class="u-text-center" >
					<image src="../../../../static/uview/example/js_select_bak.png" style="width: 100rpx;height: 100rpx;"></image>
					<view>分类</view>
				</view>
			</view>
		</uni-grid>
		<uni-group v-for="(item,index) in fen" :title="item.name">
			<uni-list>
				<uni-list-item v-for="(item1,index1) in xin[index]" link @click="dian(item1.id)" :title="item1.title"  :note="'发布时间:'+item1.createTime">
					<view slot="footer">
						<image :src="base+item1.imgUrl" style="width: 100rpx;height: 100%;"></image>
					</view>
				</uni-list-item>
			</uni-list>
		</uni-group>
	</view>
</template>

<script>
	import api from 'commer/apiURL.js'
	export default {
		data() {
			return {
				base:api.baseurl,
				lun:[],
				fen:[],
				xin:[]
			}
		},
		onLoad() {
			this.getlun()
			this.getlun2()
		},
		methods: {
			fenlei2(){
				uni.navigateTo({
					url:'fennlei'
				})
			},
			shou(){
				uni.navigateTo({
					url:'shou'
				})
			},
			getlun() {
				this.$get(this.base + '/prod-api/api/garbage-classification/ad-banner/list').then((res) => {
					res.data.forEach((item) => {
						this.lun.push({
							image: this.base + item.imgUrl,
							id: item.targetId
						})
					})
				})
			},
			dian(id){
				uni.navigateTo({
					url:'xinq?id='+id
				})
			},
			getlun2(){
				this.$get(this.base+'/prod-api/api/garbage-classification/news-type/list').then((res)=>{
					this.fen = res.rows
					const _this = this
					var i = 0
					getshu()
					function getshu(){
						if(i>= res.rows.length){
							return 
						}
						_this.$get(_this.base+'/prod-api/api/garbage-classification/news/list',{
							type:res.rows[i].id
						}).then((res)=>{
							let list = []
							list = res.rows
							_this.$set(_this.xin,i,list)
							i++
							getshu()
						})
					}
					console.log(this.xin)
				})
			}

		}
	}
</script>

<style>

</style>
